package com.lagou.lagouserviceemail.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Authther: mrwu
 * @date:2021/4/14-04
 * @Description:com.lagou.lagouserviceemail.controller
 */
@Slf4j
@RestController
public class MailController {
    @Autowired
    JavaMailSender javaMailSender;

    /**
     *
     * @param email 发送的邮箱 邮件接收者
     * @param content //发送的内容
     * @return
     */
    @GetMapping("/email")
    public boolean sendmail(@RequestParam("email") String email,@RequestParam("content") String content){
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setFrom("15210371539@163.com");
        simpleMailMessage.setTo(email);
        simpleMailMessage.setSubject("ceshi");
        simpleMailMessage.setText(content);
        try {
            javaMailSender.send(simpleMailMessage);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            log.error("发送邮件异常",e);

            return false;
        }


    }




}
